<template>
	<view class="content">
		<view class="logo">
			<text>忘记密码</text>
		</view>
		<view class="itemClass">
			<input type="number" v-model="ipone" placeholder="输入手机号" class="mui-input-clear mui-input">
		</view>
		<view class="item-code">
			<view class="code-input">
				<input type="number" v-model="code" placeholder="验证码" />
			</view>
			<span class="code-btn" v-text="codetxt" @click="getCodeTap"></span>
		</view>
		<view class="itemClass">
			<input type="password" placeholder="输入密码" v-model="password" class="mui-input-clear mui-input">
		</view>
		<view class="login" @click="loginTap">完成</view>
	</view>
</template>

<script>
	import {
		registerModel
	} from '../register.js'
	import util from '../../../common/js/util.js'
	const register = new registerModel()

	export default {
		data() {
			return {
				ipone: '',
				code: '',
				password: '',
				codetxt: '发送验证码',
				codeBtn: false
			}
		},
		methods: {
			getCodeTap() {
				if (this.codeBtn) {
					console.log('无法点击')
					return;
				} else {
					register.getCode(this.ipone, (codetxt, codeBtn) => {
						this.codetxt = codetxt;
						this.codeBtn = codeBtn;
					})
					// 调用获取短信验证方法
				}
			},
			loginTap() {
				if (!this.ipone || !this.code || !this.password) {
					util.tost('请填写完整')
					return
				}
				if (util.checkPassword(this.password)) {
					register.Forget({
							userPhone: this.ipone,
							userPwd: this.password,
							captcha: this.code
						})
						.then(res => {
							util.tost('修改成功',true)
							setTimeout(() => {
								uni.navigateBack()
							}, 1000)
						})
				}
			}
		}
	}
</script>

<style lang="scss">
	@import "../../../common/scss/reg.scss";
</style>
